package zhishuang.wang.sansi.playlist;

import zhishuang.wang.sansi.playlist.entry.AreaPositon;
import zhishuang.wang.sansi.playlist.entry.Background;
import zhishuang.wang.sansi.tools.ReturnData;

import java.util.List;

/**
 * @Author Zhishuang.Wang
 * @Date 2023/7/5 11:12
 * @Email 1406110602@qq.com
 */
public class AreaItem {
    private String id;
    private String name;
    private AreaPositon areaPositon;
    private Background background;
    private List<PlayItem> itemList;

    public AreaItem(String id, String name, AreaPositon areaPositon, List<PlayItem> itemList, Background background) {
        this.id = id;
        this.name = name;
        this.areaPositon = areaPositon;
        this.itemList = itemList;
        this.background = background;
    }

    public AreaItem(String id, String name, AreaPositon areaPositon, List<PlayItem> itemList) {
        this.id = id;
        this.name = name;
        this.areaPositon = areaPositon;
        this.itemList = itemList;
    }

    public ReturnData checkParam() {
        ReturnData rd = new ReturnData();
        rd.setCode(1);
        String errorMes = "";
        if (this.id != null && this.name != null && this.areaPositon != null && this.itemList != null && this.id.length() != 0 && this.name.length() != 0 && this.itemList.size() != 0) {
            ReturnData checkRd = null;
            checkRd = this.areaPositon.checkParam();
            if (checkRd.getCode() != 0) {
                errorMes = errorMes + "区域位置信息错误：" + checkRd.getMessage();
            }

            for(int i = 0; i < this.itemList.size(); ++i) {
                PlayItem item = (PlayItem)this.itemList.get(i);
                checkRd = item.checkParam();
                if (checkRd.getCode() != 0) {
                    errorMes = errorMes + "播放项错误信息：播放项ID：" + item.getId() + "；" + checkRd.getMessage();
                }
            }

            if (this.background != null) {
                checkRd = this.background.checkParam();
                if (checkRd.getCode() != 0) {
                    errorMes = errorMes + "区域背景信息错误：" + checkRd.getMessage();
                }
            }
        } else {
            errorMes = errorMes + "区域唯一ID、区域名称、区域位置、区域播放项等必填；";
        }

        if (errorMes != null && errorMes.length() != 0) {
            rd.setMessage(errorMes);
        } else {
            rd.setCode(0);
        }

        return rd;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public AreaPositon getAreaPositon() {
        return this.areaPositon;
    }

    public void setAreaPositon(AreaPositon areaPositon) {
        this.areaPositon = areaPositon;
    }

    public Background getBackground() {
        return this.background;
    }

    public void setBackground(Background background) {
        this.background = background;
    }

    public List<PlayItem> getItemList() {
        return this.itemList;
    }

    public void setItemList(List<PlayItem> itemList) {
        this.itemList = itemList;
    }
}